package team.southcat.wsyygh.user.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.southcat.wsyygh.common.result.Result;
import team.southcat.wsyygh.common.util.AdminInfoUtil;
import team.southcat.wsyygh.common.util.UserInfoUtil;
import team.southcat.wsyygh.model.pojo.user.LoginVo;
import team.southcat.wsyygh.model.pojo.user.User;
import team.southcat.wsyygh.model.pojo.user.UserVo;
import team.southcat.wsyygh.user.service.UserService;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Map;

@RestController
@RequestMapping("/api/user")
public class UserApiController {


    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo){
        Map<String, Object> map = userService.loginUser(loginVo);
        return Result.ok(map);
    }

    @ApiOperation("用户认证")
    @PostMapping("/auth/userAuth")
    public Result userAuth(@RequestBody User user, HttpServletRequest request){
        String userId = UserInfoUtil.getUserId(request);
        user.setId(Long.valueOf(userId));
        userService.userAuth(user);
        return Result.ok();
    }

    @GetMapping("/auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){
        String userId = UserInfoUtil.getUserId(request);
        UserVo userVo = userService.selectById(userId);
        return Result.ok(userVo);
    }

}
